#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
CAD文件生成与导出模块
"""

import ezdxf


class CADExporter:
    """
    CAD导出器类，负责将识别结果转换为DXF文件
    """
    def __init__(self):
        """
        初始化CAD导出器
        """
        pass
    
    def export_to_dxf(self, elements, output_path):
        """
        将识别的图形元素导出为DXF文件
        
        Args:
            elements (dict): 图形元素信息，来自ImageProcessor
            output_path (str): 输出DXF文件路径
        """
        # 创建新的DXF文档
        doc = ezdxf.new()
        msp = doc.modelspace()
        
        # 绘制线条
        for line in elements.get("lines", []):
            start = line["start"]
            end = line["end"]
            msp.add_line(start, end)
        
        # 绘制圆
        for circle in elements.get("circles", []):
            center = circle["center"]
            radius = circle["radius"]
            msp.add_circle(center, radius)
        
        # 保存文件
        doc.saveas(output_path)